import Vue from "vue";
import VueRouter from "vue-router";

// 解决重复点菜单报错解决办法
// const routerPush = VueRouter.prototype.push;
// VueRouter.prototype.push = function push(location) {
//     return routerPush.call(this, location).catch(error => error);
// };
if (process.env.NODE_ENV === "development") {
    Vue.use(VueRouter);
}

import { ROUTER_MODE } from "../config/app";

const err401 = r =>
    require.ensure([], () => r(require("../views/error/err401.vue")), "home");
const err404 = r =>
    require.ensure([], () => r(require("../views/error/err404.vue")), "home");
const login = r =>
    require.ensure([], () => r(require("../views/login/index.vue")), "home");
const main = r =>
    require.ensure([], () => r(require("../views/home/main.vue")), "home");

// 注意 权限字段 authRule （严格区分大小写）
export const constantRouterMap = [
    {
        path: "*",
        component: err404,
        hidden: true
    },
    {
        path: "/401",
        component: err401,
        name: "401",
        hidden: true
    },
    {
        path: "/404",
        component: err404,
        name: "404",
        hidden: true
    },
    {
        path: "/500",
        component: err404,
        name: "500",
        hidden: true
    },
    {
        path: "/login",
        component: login,
        name: "登录",
        hidden: true
    },
    {
        path: "/",
        component: resolve => require(['../views/home/index.vue'], resolve),
        redirect: "/home",
        name: "首页",
        hidden: true
    },
    {
        path: "/home",
        component: resolve => require(['../views/home/index.vue'], resolve),
        redirect: "/home/main",
        icon: "shouye",
        name: "后台管理系统",
        noDropdown: true,
        children: [
            {
                path: "main",
                component: main
            }
        ]
    }
];

export default new VueRouter({
    mode: ROUTER_MODE,
    routes: constantRouterMap,
    strict: process.env.NODE_ENV !== "production"
});

var routerMap = [
    {
        path: "/mbUser",
        redirect: "mbUser",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "yonghu",
        name: "账号管理",
        meta: {
            authRule: ["entityManagement"]
        },
        children: [
            {
                path: "mbUser",
                component: resolve => require(['../views/mbUser/mbUser.vue'], resolve),
                name: "商城管理",
                meta: {
                    authRule: ["entityManagement/list"]
                }
            },
            {
                path: "mbUserDetail",
                component: resolve => require(['../views/mbUser/mbUserDetail.vue'], resolve),
                name: "商城详情",
                hidden: true,
                meta: {
                    authRule: ["entityManagement/mbUserDetail"]
                }
            },

            {
                path: "VIP",
                name: "VIP",
                component: resolve => require(['../views/mbUser/VIP.vue'], resolve),
                hidden: true
            },
            {
                path: "vipManege",
                name: "VIP管理",
                component: resolve => require(['../views/mbUser/vipManege.vue'], resolve),
                meta: {
                    authRule: ["entityManagement/vipManege"]
                }
            },


        ]
    },
    {
        path: "/comment",
        name: "comment",
        component: resolve => require(['../views/commodity/comment.vue'], resolve),
    },

    {
        path: "/commodity",
        redirect: "classification",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "dingdan",
        name: "商品管理",
        meta: {
            authRule: ["commodity"]
        },
        children: [

            {
                path: "classification",
                component: resolve => require(['../views/commodity/classification.vue'], resolve),
                name: "商品分类",
                meta: {
                    authRule: ["commodity/classification"],
                }
            },
            {
                path: "buscommodity",
                component: resolve => require(['../views/commodity/buscommodity.vue'], resolve),
                name: "平台代理商品",
                meta: {
                    authRule: ["commodity/autarkycommodity"]
                }
            },
            {
                path: "platcommodityAudit",
                component: resolve => require(['../views/commodity/platcommodityAudit.vue'], resolve),
                name: "平台代理商品审核",
                meta: {
                    authRule: ["commodity/platcommodityAudit"]
                }
            },
            {
                path: "comment",
                component: resolve => require(['../views/commodity/comment.vue'], resolve),
                name: "评论",
                hidden: true
            },

            {
                path: "brandAgentCommodity",
                component: resolve => require(['../views/commodity/brandAgentCommodityAudit.vue'], resolve),
                name: "品牌代理商品管理",
                meta: {
                    authRule: ["commodity/brandAgentCommodity"]
                }
            }, {
                path: "distributioncommodity",
                component: resolve => require(['../views/commodity/distributionCommodity.vue'], resolve),
                name: "主营商品管理",
                meta: {
                    authRule: ["commodity/distribution"]
                }
            },
            {
                path: "relationBusinessTemplate",
                component: resolve => require(['../views/commodity/relationBusinessTemplate.vue'], resolve),
                name: "关联商家模板",
                hidden: true
            },
            {
                path: "relationCommodityTemplate",
                component: resolve => require(['../views/commodity/relationCommodityTemplate.vue'], resolve),
                name: "关联商品模板",
                hidden: true
            },
            {
                path: "relationAttributeTemplate",
                component: resolve => require(['../views/commodity/relationAttributeTemplate.vue'], resolve),
                name: "关联商品属性模板",
                hidden: true,

            },
            {
                path: "relationAttributeList",
                component: resolve => require(['../views/commodity/relationAttributeList.vue'], resolve),
                name: "商品属性模板列表",
                hidden: true
            },
            {
                path: "distributionAttract",
                component: resolve => require(['../views/commodity/distributionAttract.vue'], resolve),
                name: "主营商品审核招商",
                meta: {
                    authRule: ["commodity/distributionAttract"]
                }
                // hidden: true
            },
            {
                path: "distributionControl",
                component: resolve => require(['../views/commodity/distributionControl.vue'], resolve),
                name: "主营商品审核品控",
                meta: {
                    authRule: ["commodity/distributionControl"]
                }
                // hidden: true
            }
            
        ]
    },
    /*订单详细*/
    {
        path: "/statistics/orderdetail",
        redirect: "/statistics/orderdetail",
        component: resolve => require(['../views/home/index.vue'], resolve),
        name: "订单详细",
        hidden: true,
        children: [
            {
                path: "",
                component: resolve => require(['../views/statistics/orderdetail.vue'], resolve),
            }
        ]
    },
    {
        path: "/freightSettings",
        redirect: "settlementAgreement",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "shezhi",
        name: "系统设置",
        meta: {
            authRule: ["system"]
        },
        children: [
            {
                path: "settlementAgreement",
                component: resolve => require(['../views/system/settlementAgreement.vue'], resolve),
                name: "商家入驻协议编辑",
                meta: {
                    authRule: ["freightSettings/settlementAgreement"]
                }
            }
        ]
    },

    {
        path: "/userManage",
        redirect: "authAdmin",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "ic_opt_feature",
        name: "权限管理",
        meta: {
            authRule: ["user_manage"]
        },
        children: [
            {
                path: "authAdmin",
                component: resolve => require(['../views/userManage/admin/authAdmin.vue'], resolve),
                name: "管理员管理",
                meta: {
                    authRule: ["admin/auth/admin/index"]
                }
            },
            {
                path: "authRole",
                component: resolve => require(['../views/userManage/admin/authRole.vue'], resolve),
                name: "角色管理",
                meta: {
                    authRule: ["admin/auth/role/index"]
                }
            },
            {
                path: "updatePassword",
                component: resolve => require(['../views/userManage/admin/updatePassword.vue'], resolve),
                name: "修改密码",
                meta: {
                    authRule: ["admin/auth/role/index"]
                }
            },
            {
                path: "authPermissionRule",
                component: resolve => require(['../views/userManage/admin/authPermissionRule.vue'], resolve),
                name: "权限设置",
                meta: {
                    authRule: ["admin/auth/permission_rule/index"]
                }
            }
        ]
    },

    {
        path: "/entityAdmin",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "jiankangzhuanjia",
        redirect: "experienceEntityApplication",
        name: "商城管理",
        meta: {
            authRule: ["entityAdmin"]
        },
        children: [
            {
                path: "experienceEntityApplication",
                component: resolve => require(['../views/entityAdmin/experienceEntityApplication.vue'], resolve),
                name: "共享商城申请",
                meta: {
                    authRule: ["entityAdmin/experienceEntityApplication"]
                }
            },


            {
                path: "merchantsTemplate",
                component: resolve => require(['../views/entityAdmin/merchantsTemplate.vue'], resolve),
                name: "商家模板管理",
                meta: {
                    authRule: ["entityAdmin/merchantsTemplate"]
                }
            },
            {
                path: "goodsTemplateManager",
                component: resolve => require(['../views/entityAdmin/goodsTemplateManager.vue'], resolve),
                name: "商品模板管理",
                meta: {
                    authRule: ["entityAdmin/goodsTemplateManager"]
                }
            },
            {
                path: "goodsAttributeTemplate",
                component: resolve => require(['../views/entityAdmin/merchantsAttribute.vue'], resolve),
                name: "商品属性模板",
                meta: {
                    authRule: ["entityAdmin/merchantsAttribute"]
                }
            }

        ]
    },

    {
        path: "/order",
        redirect: "order",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "dingdan",
        name: "订单管理",
        meta: {
            authRule: ["admin/auth/order"]
        },
        children: [
            {
                path: "order",
                component: resolve => require(['../views/commodity/order.vue'], resolve),
                name: "平台订单（商户）",
                meta: {
                    authRule: ["platform/order"]
                }
            },
            {
                path: "vipOrder",
                component: resolve => require(['../views/commodity/vipOrder.vue'], resolve),
                name: "平台订单（VIP）",
                meta: {
                    authRule: ["platform/vipOrder"]
                }
            },
            {
                path: "viporderdetail",
                component: resolve => require(['../views/commodity/viporderdetail.vue'], resolve),
                name: "VIP订单详情",
                hidden: true,
            },

            {
                path: "allorder",
                component: resolve => require(['../views/commodity/allOrder.vue'], resolve),
                name: "主营订单（商户）",
                meta: {
                    authRule: ["platform/allorder"]
                }
            },
            {
                path: "vipAllOrder",
                component: resolve => require(['../views/commodity/vipAllOrder.vue'], resolve),
                name: "主营订单（VIP）",
                meta: {
                    authRule: ["platform/vipAllOrder"]
                }
            },


        ]
    },

    {
        path: "/partnershipManagement",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "jixianguanli",
        redirect: "partnershipManagement",
        name: "合伙公司管理",
        meta: {
            authRule: ["partnershipManagement"]
        },
        children: [
            {
                path: "partnershipManagement",
                component: resolve => require(['../views/partnershipManagement/partnershipManagement.vue'], resolve),
                name: "品牌合伙公司管理",
                meta: {
                    authRule: ["partnershipManagement/partnershipManagement"]
                }
            },
            // {
            //     path: "brandManagement",
            //     component: resolve => require(['../views/'], resolve),
            //     name: "品牌公司管理",
            //     meta: {
            //         authRule: ["partnershipManagement/brandManagement"]
            //     }
            // },
            // {
            //     path: "partnerManagement",
            //     component: resolve => require(['../views/'], resolve),
            //     name: "合伙人管理",
            //     meta: {
            //         authRule: ["partnershipManagement/partnerManagement"]
            //     }
            // },
            {
                path: "partnershipManagementConfig",
                component: resolve => require(['../views/partnershipManagement/partnershipManagementConfig.vue'], resolve),
                name: "公司升级配置",
                meta: {
                    authRule: [
                        "partnershipManagement/partnershipManagementConfig"
                    ]
                }
            },
            {
                path: "defaultMembership",
                component: resolve => require(['../views/partnershipManagement/defaultMembership.vue'], resolve),
                name: "默认隶属关系管理",
                meta: {
                    authRule: ["partnershipManagement/defaultMembership"]
                }
            },
            {
                path: "incubationTeam",
                component: resolve => require(['../views/partnershipManagement/incubationTeam.vue'], resolve),
                name: "平台孵化团队",
                meta: {
                    authRule: ["partnershipManagement/incubationTeam"]
                }
            },
            {
                path: "addPpartnership",
                component: resolve => require(['../views/partnershipManagement/addPpartnership.vue'], resolve),
                name: "品牌公司(网状图)",
                meta: {
                    authRule: ["partnershipManagement/addPpartnership"]
                }
            }
        ]
    },

    {
        path: "/levelAudit",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "yonghu",
        redirect: "promotionApplicationRecord",
        name: "商户晋升",
        meta: {
            authRule: ["levelAudit"]
        },
        children: [
            {
                path: "promotionApplicationRecord",
                component: resolve => require(['../views/levelAudit/promotionApplicationRecord.vue'], resolve),
                name: "晋升申请记录",
                meta: {
                    authRule: ["levelAudit/promotionApplicationRecord"]
                }
            },
            // {
            //     path: "globalCompany",
            //     component: resolve => require(['../views/'], resolve),
            //     name: "全球公司管理",
            //     meta: {
            //         authRule: ["levelAudit/globalCompany"]
            //     }
            // },
            {
                path: "applyTakeEffect",
                component: resolve => require(['../views/levelAudit/applyTakeEffect.vue'], resolve),
                name: "申请生效管理",
                meta: {
                    authRule: ["levelAudit/applyTakeEffect"]
                }
            },
            {
                path: "incubationEffect",
                component: resolve => require(['../views/levelAudit/incubationEffect.vue'], resolve),
                name: "孵化申请生效管理",
                // hidden: true,
                meta: {
                    authRule: ["levelAudit/incubationEffect"]
                }
            },
            {
                path: "setTimeRule",
                component: resolve => require(['../views/levelAudit/setTimeRule.vue'], resolve),
                name: "定时任务规则",
                meta: {
                    authRule: ["levelAudit/setTimeRule"]
                }
            },
        ]
    },
    {
        path: "/incubation",
        component: resolve => require(['../views/home/index.vue'], resolve),
        redirect: "incubation",
        icon: "yonghu",
        name: "孵化公司流程",
        meta: {
            authRule: ["incubation"]
        },
        children: [
            {
                path: "incubation",
                component: resolve => require(['../views/incubation/incubation.vue'], resolve),
                name: "公司孵化规则设置",
                meta: {
                    authRule: ["incubation/incubation"]
                }
            },
            {
                path: "incubationStep",
                component: resolve => require(['../views/incubation/incubationStep.vue'], resolve),
                name: "公司孵化申请管理",
                meta: {
                    authRule: ["incubation/incubationStep"]
                },
            },
            {
                path: "createIncubationStep",
                component: resolve => require(['../views/incubation/createIncubationStep'], resolve),
                name: "组建孵化公司申请",
                // hidden: true,
                meta: {
                    authRule: ["incubation/createIncubationStep"]
                },
            },
            {
                path: "incubationRecord",
                component: resolve => require(['../views/incubation/incubationRecord'], resolve),
                name: "公司孵化记录",
                // hidden: true,
                meta: {
                    authRule: ["incubation/incubationRecord"]
                },
            },
            {
                path: "searchEntity",
                component: resolve => require(['../views/incubation/searchEntity'], resolve),
                name: "公司孵化新增商城查询",
                hidden: true,
                meta: {
                    authRule: ["incubation/searchEntity"]
                },
            },
            {
                path: "addEntity",
                component: resolve => require(['../views/incubation/addEntity'], resolve),
                name: "新增商城页面",
                hidden: true,
                meta: {
                    authRule: ["incubation/addEntity"]
                },
            },

            {
                path: "appendEntity",
                component: resolve => require(['../views/incubation/appendEntity'], resolve),
                name: "可参与孵化活动商城隶属县级品牌公司列表",
                hidden: true,
                meta: {
                    authRule: ["incubation/appendEntity"]
                },
            },
            {
                path: "addBusList",
                component: resolve => require(['../views/incubation/addBusList'], resolve),
                name: "县级品牌公司列表",
                hidden: true,
                meta: {
                    authRule: ["incubation/addBusList"]
                },
            },

        ]
    },

    {
        path: "/handWork",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "caidanshezhi",
        redirect: "setRelation",
        name: "手工排网设置",
        meta: {
            authRule: ["handWork"]
        },
        children: [
            {
                path: "setRelation",
                component: resolve => require(['../views/handWork/setRelation'], resolve),
                name: "公司关系设置",
                meta: {
                    authRule: ["handWork/setRelation"]
                }
            },
            {
                path: "developmentRelation",
                component: resolve => require(['../views/handWork/developmentRelation'], resolve),
                name: "开发关系查询",
                hidden: true,
                meta: {
                    authRule: ["handWork/developmentRelation"]
                }
            },
            {
                path: "addCreater",
                component: resolve => require(['../views/handWork/addCreater'], resolve),
                name: "创始人添加",
                hidden: true,
                meta: {
                    authRule: ["handWork/addCreater"]
                }
            },
            {
                path: "setRelationRecord",
                component: resolve => require(['../views/handWork/setRelationRecord'], resolve),
                name: "公司关系设置记录",
                hidden: true,
                meta: {
                    authRule: ["handWork/setRelationRecord"]
                }
            },
            {
                path: "editInfo",
                component: resolve => require(['../views/handWork/editInfo'], resolve),
                name: "公司信息编辑",
                hidden: true,
                meta: {

                    keepAlive: true,
                    authRule: ["handWork/editInfo"]
                }
            },
            {
                path: "lookInfo",
                component: resolve => require(['../views/handWork/lookInfo'], resolve),
                name: "查看公司信息",
                hidden: true,
                meta: {
                    authRule: ["handWork/lookInfo"]
                }
            },
            {
                path: "addCompany",
                component: resolve => require(['../views/handWork/addCompany'], resolve),
                name: "新增品牌公司",
                hidden: true,
                meta: {
                    keepAlive: true,
                    authRule: ["handWork/addCompany"]
                }
            },
            {
                path: "serchCompany",
                component: resolve => require(['../views/handWork/serchCompany'], resolve),
                name: "品牌公司查询列表",
                hidden: true,
                meta: {
                    authRule: ["handWork/serchCompany"]
                }
            }


        ]
    },
    {
        path: "/financialManagement",
        redirect: "capitalDetails",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "anzhanghaotongji",
        name: "财务信息管理",
        meta: {
            authRule: ["financialManagement"]
        },
        children: [
            {
                path: "capitalDetails",
                component: resolve => require(['../views/FinancialManagement/capitalDetails'], resolve),
                name: "资金明细管理",
                meta: {
                    authRule: ["financialManagement/capitalDetails"]
                }
            },
            {
                path: "fundsDetail",
                component: resolve => require(['../views/FinancialManagement/fundsDetail/fundsDetail'], resolve),
                name: "商城资金明细",
                hidden: true,
                meta: {
                    authRule: ["financialManagement/fundsDetail"]
                },
            },
            {
                path: "Payment",
                component: resolve => require(['../views/FinancialManagement/Payment'], resolve),
                name: "付款申请",
                meta: {
                    authRule: ["financialManagement/Payment"]
                },
            },
            {
                path: "Settlement",
                component: resolve => require(['../views/FinancialManagement/Settlement'], resolve),
                name: "结款申请",
                meta: {
                    authRule: ["financialManagement/Settlement"]
                },
            },
            {
                path: "paymentApproval",
                component: resolve => require(['../views/FinancialManagement/paymentApproval'], resolve),
                name: "付款申请审核",
                meta: {
                    authRule: ["financialManagement/paymentApproval"]
                },
            },
            {
                path: "SettlementProcessing",
                component: resolve => require(['../views/FinancialManagement/SettlementProcessing'], resolve),
                name: "结款申请处理",
                meta: {
                    authRule: ["financialManagement/SettlementProcessing"]
                },
            },
            {
                path: "SettlementApproval",
                component: resolve => require(['../views/FinancialManagement/SettlementApproval'], resolve),
                name: "结款申请审核",
                meta: {
                    authRule: ["financialManagement/SettlementApproval"]
                },
            },
            {
                path: "transferFund",
                component: resolve => require(['../views/FinancialManagement/transferFund'], resolve),
                name: "商城资金调整",
                meta: {
                    authRule: ["financialManagement/transferFund"]
                },
            },
            {
                path: "entityQuery",
                component: resolve => require(['../views/FinancialManagement/entityQuery'], resolve),
                name: "商户查询",
                hidden: true,
                meta: {
                    authRule: ["financialManagement/entityQuery"]
                },
            },
            {
                path: "cardManagement",
                component: resolve => require(['../views/FinancialManagement/cardManagement'], resolve),
                name: "管家卡管理",
                meta: {
                    authRule: ["financialManagement/cardManagement"]
                },
            },
            {
                path: "taxation",
                component: resolve => require(['../views/FinancialManagement/taxation'], resolve),
                name: "商家税务管理",
                // hidden: true,
                meta: {
                    authRule: ["financialManagement/taxation"]
                },
            },
            {
                path: "taxationDetail",
                component: resolve => require(['../views/FinancialManagement/taxationDetail'], resolve),
                name: "扣税明细",
                hidden: true,
                meta: {
                    authRule: ["financialManagement/taxationDetail"]
                },
            }


        ]
    },
    {
        path: "/alliance",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "dangqianhuodonggaojing",
        redirect: "promotionApplicationToexamine",
        name: "联盟管理",
        meta: {
            authRule: ["alliance"]
        },
        children: [

            {
                path: "promotionApplicationToexamine",
                component: resolve => require(['../views/alliance/promotionApplicationToexamine.vue'], resolve),
                name: "晋升申请管理",
                meta: {
                    authRule: ["alliance/promotionApplicationToexamine"]
                }
            },
            {
                path: "companyAdmin",
                component: resolve => require(['../views/alliance/companyAdmin'], resolve),
                name: "公司管理",
                meta: {
                    authRule: ["alliance/companyAdmin"]
                }
            },
            {
                path: "createCompanyWill",
                component: resolve => require(['../views/alliance/createCompanyWill'], resolve),
                name: "组建公司意愿管理",
                meta: {
                    authRule: ["alliance/createCompanyWill"]
                }
            },
        ]
    },
    {
        path: "/versionControl",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "dangqianhuodonggaojing",
        redirect: "controlVersion",
        name: "版本管理",
        meta: {
            authRule: ["versionControl"]
        },
        children: [
            {
                path: "controlVersion",
                component: resolve => require(['../views/versionControl/controlVersion'], resolve),
                name: "APP版本管理",
                meta: {
                    authRule: ["versionControl/controlVersion"]
                }
            },
        ]
    },



];

// 本地开发环境开放权限设置 仅限开发人员使用
// if (process.env.NODE_ENV === "development") {
//     routerMap[routerMap.length - 1].children.push({
//         path: "authPermissionRule",
//         component: resolve => require(['../views/'], resolve),
//         name: "权限设置",
//         hidden: true,
//         meta: {
//             authRule: ["admin/auth/permission_rule/index"]
//         }
//     });
// }

export const asyncRouterMap = routerMap;
